<template>
	<view class="forum">
		<view class="forum_t">
			<uni-nav-bar title="研学说" statusBar :border="false"></uni-nav-bar>
			<view class="talk">
				<view class="talk_title">话题</view>
				<view class="talk_list">
					<scroll-view class="scroll-view" scroll-x="true">
						<block v-for="(item,i) in gambitList" :key="i">
							<view class="talk_item">
								<view class="" @tap="handleTalkDetail(item.id)">
									<image class="talk_img" :src="item.picture.split(',')[0]" mode="aspectFill"></image>
									<view class="title">{{item.name}}</view>
									<view class="join_count">
										<text>{{item.replyNum}}</text>
										<uni-icons type="right" color="#999" size="10"></uni-icons>
									</view>
								</view>
							</view>
						</block>
					</scroll-view>
				</view>
			</view>
			<view class="tabs">
				<scroll-view class="scroll-view" scroll-x="true">
					<block v-for="item in tabs" :key="item.val">
						<view class="tab_item" @tap="clickTabs(item)">
							<view class="">
								<view class="tab_name" :class="{'active_name':currentType==item.val}">{{item.name}}
								</view>
								<image src="/static/forum/xiaquxian.png" mode=""
									:class="{'active_line':currentType==item.val}"></image>
							</view>
						</view>
					</block>
				</scroll-view>
			</view>
		</view>
		<view class="list">
			<block v-for="(item,i) in list" :key="i">
				<view class="item" @tap="$to(`/pages/forum/evaluaTetrends/evaluaTetrends?id=${item.id}`)">
					<view class="item_t">
						<view class="author">
							<image :src="item.avatar" mode="aspectFill"></image>
							<view class="">
								<view class="author_name">{{item.realName}}</view>
								<view class="time">{{item.createTime}}</view>
							</view>
						</view>
					</view>
					<view class="item_m">
						<!-- <view class="article_text">
							{{item.content}}
						</view> -->
						<view class="article_text" v-html="item.content"></view>
						<view class="article_imgs" v-if="item.image&&item.type==1">
							<block v-for="(img,idx) in item.image?item.image.split(','):[]" :key="idx">
								<image :src="img" mode="aspectFill" />
							</block>
						</view>
						<view class="article_imgs" v-if="item.type==2">
							<video :src="item.video" controls></video>
						</view>
					</view>
					<view class="item_b">
						<view class="">
							<uni-icons v-if="item.likeType" type="heart-filled" color="red" size="20"></uni-icons>
							<uni-icons v-if="!item.likeType" type="heart" size="20"></uni-icons>
							<text>{{item.likeNum}}</text>
						</view>
						<view class="">
							<image src="/static/forum/pinglun.png" mode=""></image>
							<text>{{item.replyNum}}</text>
						</view>
						<view class="">
							<image src="../../static/mine/fenxiang.png" mode=""></image>
							<text>{{item.shareNum}}</text>
						</view>
					</view>
				</view>
			</block>
			<view style="text-align: center;font-size: 26rpx;" v-if="list.length==0">
				<image style="width: 200rpx;height: 200rpx;" src="../../static/nodata.png"></image>
				<view style="color: #999;text-align: center;" v-if="isLogin">暂无数据</view>
				<block v-else>
					<view style="color: #999;text-align: center;" >登录后即可发布~</view>
					<button class="btn">去登录</button>
				</block>
			</view>
			<view style="text-align: center;color: #999;" v-if="noMoreData&&list.length!=0">
				没有更多啦
			</view>
		</view>
		<view class="releaseBtn" >
			<image src="/static/forum/release.png" @click="$to('/pages/index/release/release?pagetype=研学说')"></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabs: [{
					name: '老师发布',
					val: 1
				}, {
					name: '家长发布',
					val: 2
				}],
				currentType: 1,
				gambitList: [],
				list: [],
				noMoreData: false,
				lastPage: 1,
				page: 1,
				isLogin: '',
			}
		},
		onLoad() {
		},
		onShow() {
			this.getGambitList()
			this.isLogin = uni.getStorageSync('token')? true : false;
		},
		onReachBottom() {
			if (this.page < this.lastPage) {
				this.page += 1
				this.getlist()
			} else {
				this.noMoreData = true
			}
		},
		methods: {
			async getlist() {
				const res = await this.$api.get('community/note/page/list', {
					limit: 10,
					page: this.page,
					parentsType: this.currentType
				});
				// console.log(res, "研学说列表")
				if (res.code == 200) {
					const { list,totalPage } = res.data
					if (this.page == 1) {
						this.list = list || [];
						this.lastPage = totalPage || 1;
					} else {
						this.list.push(...list);
					}
					this.page != 1 && list.length == 0 ? this.noMoreData = true : this.noMoreData = false
				}
			},
			getImg(imgs, type) {
				const imageLisit = imgs.split(',')
				if (type === 'all') {
					return imageLisit
				} else {
					return imageLisit[0]
				}
			},
			async getGambitList() {
				const res = await this.$api.get('community/topic/recommend/list', {});
				// console.log(res, "话题")
				if (res.code == 200) {
					this.gambitList = res.data;
					this.page = 1
					this.getlist()
				}
			},
			clickTabs(item) {
				this.currentType = item.val
				this.page = 1
				this.getlist()
			},
			handleTalkDetail(id) {
				this.$to(`/pages/forum/evaluateTalk/evaluateTalk?id=${id}`)
			},
			previewImg(current,urls) {
				uni.previewImage({
					current,
					urls
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F7F7;
	}

	video {
		width: 100%;
		height: 400rpx;
	}

	.releaseBtn {
		position: fixed;
		top: 60vh;
		right: 30rpx;

		image {
			width: 100rpx;
			height: 100rpx;
		}
	}

	.forum {
		position: relative;

		.forum_t {
			width: 100%;
			background: linear-gradient(to bottom, #E7F0FF, #F7F7F7);
			padding-bottom: 20rpx;
			position: fixed;
			left: 0;
			right: 0;
			top: 0;
			z-index: 2;

			/deep/.uni-navbar {
				// opacity: 0;
				.uni-navbar__content {
					background-color: transparent !important;

					.uni-navbar__header {
						background-color: transparent !important;
					}
				}
			}

			.talk {
				.talk_title {
					font-size: 26rpx;
					font-weight: bold;
					padding: 24rpx 26rpx;
					box-sizing: border-box;
				}

				.talk_list {
					display: flex;
					align-items: center;
					height: 164rpx;
					overflow: hidden;
					margin-bottom: 54rpx;

					.scroll-view {
						white-space: nowrap;
						width: 100%;

						.talk_item {
							display: inline-block;
							width: 200rpx;
							margin: 10rpx;
							padding: 20rpx 0;
							box-sizing: border-box;

							>view {
								width: 200rpx;
								height: 160rpx;
								background-color: #fff;
								border-radius: 14rpx;
								padding: 11rpx 18rpx;
								box-sizing: border-box;
							}

							.talk_img {
								width: 66rpx;
								height: 66rpx;
								border-radius: 50%;
							}

							.title {
								font-size: 26rpx;
								font-weight: bold;
								line-height: 26rpx;
								padding: 8rpx 0 12rpx;
							}

							.join_count {
								display: flex;
								justify-content: space-between;
								align-items: center;
								font-size: 22rpx;
								line-height: 22rpx;
								color: #999999;
							}
						}

						.talk_item:first-child {
							margin-left: 20rpx;
						}

						.talk_item:last-child {
							margin-right: 20rpx;
						}
					}
				}
			}

			.tabs {
				padding: 0 26rpx;
				box-sizing: border-box;
				height: 60rpx;
				overflow: hidden;
				display: flex;
				align-items: center;

				.scroll-view {
					white-space: nowrap;
					width: 100%;

					.tab_item {
						padding: 20rpx 0;
						display: inline-block;

						>view {
							display: flex;
							flex-direction: column;
							align-items: center;

							.tab_name {
								font-size: 26rpx;
								font-weight: 500;
								color: #999999;
							}

							.active_name {
								font-size: 32rpx;
								font-weight: bold;
								color: #212121;
							}

							image {
								width: 35rpx;
								height: 16rpx;
								opacity: 0;
							}

							.active_line {
								opacity: 1;
							}
						}
					}

					.tab_item:not(:last-child) {
						margin-right: 64rpx;
					}
				}
			}
		}


		.list {
			padding: 530rpx 26rpx 30rpx;
			box-sizing: border-box;

			.item {
				padding: 16rpx 26rpx 20rpx;
				box-sizing: border-box;
				border-radius: 20rpx;
				background-color: #fff;
				margin-bottom: 20rpx;

				.item_t {
					display: flex;
					justify-content: space-between;

					.author {
						display: flex;
						align-items: center;

						image {
							width: 80rpx;
							height: 80rpx;
							border-radius: 50%;
							margin-right: 14rpx;
							background-color: #F7F7F7;
						}

						.author_name {
							font-size: 30rpx;
							line-height: 30rpx;
							font-weight: bold;
							margin-bottom: 14rpx;
						}

						.time {
							font-size: 24rpx;
							line-height: 24rpx;
							color: #B3B3B3;
						}
					}
				}

				.item_m {
					padding: 20rpx 0;

					.article_text {
						font-size: 26rpx;
						line-height: 40rpx;
						margin-bottom: 16rpx;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}

					.article_imgs {
						image {
							width: 206rpx;
							height: 200rpx;
							border-radius: 20rpx;
							background-color: #F7F7F7;
						}

						image:not(:last-child) {
							margin-right: 12rpx;
						}
					}
				}

				.item_b {
					font-size: 24rpx;
					color: #999999;
					line-height: 24rpx;
					display: flex;
					justify-content: space-between;

					>view {
						display: flex;
						align-items: center;

						image {
							width: 34rpx;
							height: 34rpx;
						}

						text {
							font-size: 24rpx;
							margin-left: 12rpx;
						}
					}

					.read_count {
						color: #999999;
						font-size: 24rpx;
					}
				}
			}
		
			.btn {
				margin: 0 auto;
				margin-top: 40rpx;
				width: 200rpx;
				height: 74rpx;
				border-radius: 14rpx;
				text-align: center;
				line-height: 74rpx;
				background-color: #2E80FE;
				font-size: 26rpx;
				color: #FFFFFF;
			}
		}
	}
</style>